﻿
namespace KingdessServices.Model
{
    public class ApiResult
    {
        public ApiResult()
        {
            code = ApiErrorCode.OK;
            msg = "OK";
        }

        public ApiResult(ApiErrorCode code, string msg)
        {
            this.code = code;
            this.msg = msg;
            this.data = null;
        }

        public ApiResult(ApiErrorCode code, string msg, object data)
        {
            this.code = code;
            this.msg = msg;
            this.data = data;
        }

        /// <summary>
        /// 返回类型，1=成功，-1=失败，-2=异常
        /// </summary>
        public ApiErrorCode code { get; set; }

        /// <summary>
        /// 返回错误信息
        /// </summary>
        public string msg { get; set; } = string.Empty;

        /// <summary>
        /// 返回对象（实体或字符串）
        /// </summary>
        public object data { get; set; }

        /// <summary>
        /// 请求随机码（用于排查错误）
        /// </summary>
        public string randNumber { get; set; }

        /// <summary>
        /// 是否成功
        /// </summary>
        /// <returns></returns>
        public bool IsSuccess() { return code == ApiErrorCode.OK; }
    }
}
